package com.browner.game;
import java.util.*;

public class Player {
	
	private static Random rand = new Random();
	private static Scanner in = new Scanner(System.in);
	
	private int health;
	private int maxHealth;
	private String name;
	private int attack;
	private int defense;
	private int level;
	
	public Player() {
		health = 20;
		maxHealth = health;
		name = "Steve";
		attack = 0;
		defense = 0;
		level = 1;
	}
	
	public Player(String name1, int health1) {
		health = health1;
		maxHealth = health1;
		name = name1;
		attack = 0;
		defense = 0;
		level = 1;
	}
	
	public void setHealth(int health1) {
		health = health1;
	}
	
	public int getHealth() {
		return health;
	}
	
	public void addMaxHealth(){
		maxHealth += 10;
		System.out.println("Your max health increased by 10 to"+maxHealth+".");
		try{Thread.sleep(2000);}catch(Exception e){return;}
	}
	
	public int getMaxHealth() {
		return health;
	}
	
	public String getName() {
		return name;
	}
	
	public int getAtatck() {
		return attack;
	}
	
	public void addAttack() {
		attack++;
		System.out.println("Attack increased by 1 to "+attack+".");
	}
	
	public int getDefense() {
		return defense;
	}
	
	public void addDefense() {
		defense++;
		System.out.println("Defense increased by 1 to "+defense+".");
	}
	
	public int getLevel() {
		return level;
	}
	
	public void levelUp() {
		level++;
		System.out.println("You levelled up! Your level is now "+level+".");
		System.out.println("A mysterious force has healed you to max health.");
		try{Thread.sleep(2000);}catch(Exception e){}
		boolean done = false;
		while(!done) {
			done = true;
			System.out.println("Select a stat to increase. (attack/defense/health): ");
			String choice = in.next();
			if(choice.equalsIgnoreCase("attack"))
				addAttack();
			else if(choice.equalsIgnoreCase("defense"))
				addDefense();
			else if(choice.equalsIgnoreCase("health"))
				addMaxHealth();
			else {
				System.out.println("Please enter a valid option.");
				done = false;
			}
		}
		fullHeal();
	}
	
	public int attack(int enemyDef) {
		int dmg = rand.nextInt(10) + 1 + attack - enemyDef;
		System.out.println("You did "+dmg+" damage!");
		return dmg;
	}
	
	//returns true if you die, else returns false
	public boolean damage(int dmg) {
		health -= dmg + defense;
		if(health <= 0) {
			health = 0;
			return true;
		}
		else return false;
	}
	
	public void heal() {
		int health1 = level*8 + rand.nextInt(6);
		health += health1;
		if(health > maxHealth)
			health = maxHealth;
		System.out.println("You gained "+health1+" health. You now have "+health+" health.");
	}
	
	public void fullHeal() {
			health = maxHealth;
	}
	
	public void loseGame() {
		System.out.println("\nYou died and lost the game.");
		System.out.println("Please show the programmer your score so he may put it into the high score list once one is created.");
		System.out.println("Score: &e0");
		System.exit(0);
	}
	
	public void winGame() {
		System.out.println("\nCongratulations! You won the game, "+name+"!");
		System.out.println("Please show the programmer your score so he may put it into the high score list once one is created.");
		System.out.println("Score: &e0");
		System.exit(0);
	}
}
